package cs3343.project.family;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * The Class Clock.
 */
public class Clock {
	
	/** The calendar. */
	private Calendar calendar;
	
	/** The hour. */
	private int hour;
	
	/** The minute. */
	private int minute;
	
	/** The second. */
	private int second;
	
	/** The date. */
	private int day;
	
	/** The month. */
	private int month;
	
	/** The year. */
	private int year;
	
	/**
	 * Instantiates a new clock.
	 */
	public Clock() {
		calendar = new GregorianCalendar();  
		currentTime();
		currentDate();
	}
	
	/**
	 * Instantiates a new clock.
	 *
	 * @param hour the hour
	 * @param minute the minute
	 * @param second the second
	 */
	public Clock(int hour, int minute, int second) {
		this.hour = hour;  
        this.minute = minute;  
        this.second = second;
	}
	
	/**
	 * Gets the current time.
	 *
	 * @return the current time
	 */
	public void currentTime() {
		hour = calendar.get(Calendar.HOUR_OF_DAY);  
        minute = calendar.get(Calendar.MINUTE);  
        second = calendar.get(Calendar.SECOND);
	}
	
	/**
	 * Gets the current date.
	 *
	 * @return the current date
	 */
	public void currentDate() {
		day = calendar.get(Calendar.DAY_OF_MONTH);
		month = calendar.get(Calendar.MONTH) + 1;
		year = calendar.get(Calendar.YEAR);
	}
	
	/**
	 * Gets the current time.
	 *
	 * @return the current time
	 */
	public String getCurrentTime() {
		currentTime();
		return String.format("%1$02d:%2$02d:%3$02d", hour, minute, second);
	}
	
	/**
	 * Gets the current date.
	 *
	 * @return the current date
	 */
	public String getCurrentDate() {
		currentDate();
		return String.format("%1$04d-%2$02d-%3$02d", year, month, day);
	}
	
	/**
	 * To date time.
	 *
	 * @return the string
	 */
	public String toDateTime() {
		return String.format("%1$04d%2$02d%3$02d_%4$02d%5$02d%6$02d", year, month, day, hour, minute, second);
	}
	
	/**
	 * To date.
	 *
	 * @return the string
	 */
	public String toDate() {
		return String.format("%1$04d%2$02d%3$02d", year, month, day);
	}
	
	/**
	 * To time.
	 *
	 * @return the string
	 */
	public String toTime() {
		return String.format("%1$02d%2$02d%3$02d", hour, minute, second);
	}
	
	/**
	 * Gets the hour.
	 *
	 * @return the hour
	 */
	public int getHour() {
		return hour;
	}

	/**
	 * Sets the hour.
	 *
	 * @param hour the new hour
	 */
	public void setHour(int hour) {
		this.hour = hour;
	}

	/**
	 * Gets the minute.
	 *
	 * @return the minute
	 */
	public int getMinute() {
		return minute;
	}

	/**
	 * Sets the minute.
	 *
	 * @param minute the new minute
	 */
	public void setMinute(int minute) {
		this.minute = minute;
	}

	/**
	 * Gets the second.
	 *
	 * @return the second
	 */
	public int getSecond() {
		return second;
	}

	/**
	 * Sets the second.
	 *
	 * @param second the new second
	 */
	public void setSecond(int second) {
		this.second = second;
	}
}
